/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.oracleandsxnd.erp.member.service;

import com.oracleandsxnd.erp.common.persistence.Page;
import com.oracleandsxnd.erp.common.service.CrudService;
import com.oracleandsxnd.erp.member.dao.MemberMoneyGiveDao;
import com.oracleandsxnd.erp.member.entity.Member;
import com.oracleandsxnd.erp.member.entity.MemberMoneyGive;
import com.oracleandsxnd.erp.member.entity.MemberMoneyLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 会员充值Service
 * @author 会员充值
 * @version 2019-12-14
 */
@Service
@Transactional(readOnly = true)
public class MemberMoneyGiveService extends CrudService<MemberMoneyGiveDao, MemberMoneyGive> {

	public MemberMoneyGive get(String id) {
		return super.get(id);
	}
	
	public List<MemberMoneyGive> findList(MemberMoneyGive memberMoneyGive) {
		return super.findList(memberMoneyGive);
	}
	
	public Page<MemberMoneyGive> findPage(Page<MemberMoneyGive> page, MemberMoneyGive memberMoneyGive) {
		return super.findPage(page, memberMoneyGive);
	}
	@Autowired
	private MemberService memberService;

	@Autowired
	private MemberMoneyLogService memberMoneyLogService;

	@Transactional(readOnly = false)
	public void save(MemberMoneyGive memberMoneyGive) {
		Member m=memberService.get(memberMoneyGive.getMemberid());
		double money= m.getMoney();
		double lmoney=0d;

		lmoney=money+memberMoneyGive.getMoney();

		m.setMoney(lmoney);
		memberService.save(m);
		MemberMoneyLog memberMoneyLog=new MemberMoneyLog();
		memberMoneyLog.setMemberid(m.getId());
		memberMoneyLog.setMembername(m.getName());
		memberMoneyLog.setMoney(memberMoneyGive.getMoney());
		memberMoneyLog.setLastmoney(lmoney);
		memberMoneyLogService.save(memberMoneyLog);
		memberMoneyGive.setMembername(m.getName());
		super.save(memberMoneyGive);
	}
	
	@Transactional(readOnly = false)
	public void delete(MemberMoneyGive memberMoneyGive) {
		super.delete(memberMoneyGive);
	}

	public Page<MemberMoneyGive> findtjPage(Page<MemberMoneyGive> memberMoneyGivePage, MemberMoneyGive memberMoneyGive) {
		memberMoneyGive.setPage(memberMoneyGivePage);
		memberMoneyGivePage.setList(dao.findtjList(memberMoneyGive));
		return memberMoneyGivePage;
	}
}